#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

#define BOARD_WIDTH 10
#define BOARD_HEIGHT 20
#define BLOCK_SIZE 4 
typedef struct {
    int x;
    int y;
    int shape[BLOCK_SIZE][BLOCK_SIZE];
} Block;
Block currentBlock;
void initBlock(Block *block, int s) {
	if(s == 1){
		block -> shape[0][0] = 1; 
		block -> shape[0][1] = 1; 
		block -> shape[0][2] = 1; 
		block -> shape[0][3] = 1; 
	}
    block->x = (BOARD_WIDTH - BLOCK_SIZE) / 2;
    block->y = 0;
}

void printBoard(const Block *block) {
    for (int y = 0; y < BOARD_HEIGHT; ++y) {
        for (int x = 0; x < BOARD_WIDTH; ++x) {
            if (block->y + y >= 0 && block->y + y < BOARD_HEIGHT &&
                block->x + x >= 0 && block->x + x < BOARD_WIDTH) {
                if (block->shape[y][x]) {
                    printf("*");
                } else {
                    printf(" ");
                }
            } else {
                printf(" ");
            }
        }
        printf("\n");
    }
}

void moveBlock(Block *block, int dx, int dy) {
    block->x += dx;
    block->y += dy;
}

void alarmHandler(int signum) {
    system("clear");
    moveBlock(&currentBlock, 0, 2);
    printBoard(&currentBlock);
    //fflush(stdout);
    alarm(1);
}
int main() {
    initBlock(&currentBlock, 1);
    signal (SIGALRM, alarmHandler);
    alarm(1);
    getchar();
    return 0;
}
